package com.vcc.data.mapper;


import com.mybatisflex.core.BaseMapper;
import com.vcc.core.model.AmountData;
import com.vcc.core.model.CountData;
import com.vcc.data.entity.Transaction;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface TransactionMapper extends BaseMapper<Transaction> {

    @Select("select DATE_FORMAT(create_date,'%Y-%m-%d') as date ,count(*) as count from vcc_auth_tran v1 where v1.user_id = #{userId} and status = 'APPROVED' group by date order by date desc limit 30")
    List<CountData> successCountById(@Param("userId")Long userId);


    @Select("select DATE_FORMAT(create_date,'%Y-%m-%d') as date ,count(*) as count from vcc_auth_tran v1 where v1.user_id = #{userId} group by date order by date desc limit 30")
    List<CountData> countById(@Param("userId")Long userId);


    @Select("select DATE_FORMAT(create_date,'%Y-%m-%d') as date ,sum(billing_amount) as amount from vcc_auth_tran v1 where v1.user_id = #{userId} and status = 'APPROVED' group by date order by date desc limit 30")
    List<AmountData> successAmountById(@Param("userId")Long userId);


    @Select("select tran_id from vcc_transaction where channel_tran_id = #{channelTranId}")
    public String getTranIdByChannelTranId(@Param("channelTranId") String channelTranId);
}

